Software exception handling is a programming language construct designed to handle the occurrence of some exceptional condition that changes the normal flow of execution. Exceptional conditions may include, but are not limited to, an attempt to divide by zero and/or an attempt to access a non-existent file. When the occurrence of an exception is signaled, the stack of function calls is unwound until the appropriate exception handler is found. Programming language interpreters and compilers that support exception handling typically insert code to handle the stack unwind in case of the occurrence of an exception when translating source code into one or more various types of intermediate representations.
For example, in the C++ programming language an exception is triggered by the “throw” keyword. The scope of exception handlers in the C++ programming language are delineated with the keywords “try” (marking the beginning of the scope of an exception handler) and “catch” (marking the end of the scope of an exception handler). In C++, during a stack unwind the lifetime of local objects in an unwound function ends. C++ guarantees that the destructor for each of these local objects will be called during a stack unwind due to the occurrence of an exception. Thus, the code inserted by the C++ compiler to handle a stack unwind in case of the occurrence of an exception will include calling the destructors for all local objects in the function to be unwound.